Zero1000

Score-Vue

01: アルゴリズム
3: no entryの処理



1. total0の完成

index.html
function newCnt(entry,cnt){
	
	cnt2=entry.indexOf(0,cnt+1)
	
	return cnt2
}






function newEntry(ary,l){
	 
	 out=ary.map(  e=>  {if(e>l){return 1} else{return 0} }  )
	 
	 return out
}



function newArray(x){
	
	return new Array(x).fill(0)
}	


function add(x,y){
	
	l=x.length
	
	out=[]
	
	for(i=0;i<l;i++){
		out.push(x[i]+y[i])
	}
	


	return out
	
}

function remake(a){
	let l=a.length	
	let out=[]
	for(let i=0;i<l;i++ ){ out.push(a[i])}
	return out
	
}
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
<script src="func.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.9/lodash.min.js"></script>

<style>
.c1{ color: red}
.c2{color: blue}
</style>

<div id="app">
	
{{cnt+1}}/{{len}}({{turn}})<br>
shresh:{{shresh}}<br>

<h3>{{quiz[cnt]}}</h3>
<hr>

entry:
<span v-for="(e,i) in entry"  v-bind:class="i==cnt  ? c1:c2">
{{e}}</span>

<br>

score:
<span v-for="(e,i) in score"  v-bind:class="i==cnt  ? c1:c2">
{{e}}</span>

<br>

total:
<span v-for="(e,i) in total"  v-bind:class="i==cnt  ? c1:c2">
{{e}}</span>

<hr>


entry0:{{ entry0}}<br>




score0:{{score0}}<br>


total0:{{total0}}<br>


<hr>


<button @click='bt(0)'>正</button>
<button @click='bt(1)'>誤</button>

</div>

<script>
	
quiz=["0 AA","1 BB","2 CC"]
len=quiz.length

score=new Array(len).fill(0)
score0=new Array(len).fill(0)

entry=new Array(len).fill(0)
total=new Array(len).fill(0)



new Vue({
	
  el: "#app",
  
  data: {
	shresh:2,
	
  	quiz:quiz,
  	cnt:0,
  	turn:0,
  	
  	score:score,
  	score0:score,
  	
  	entry:entry,
  	entry0:entry,
  	
  	total:total,
  	total0:[0,0,0],


	len:len,
	c1:'c1',
	c2:'c2',
  },
  
  methods:{
	  
	bt:function(x){ 
		
		//------ cnt設定--------
		newC0=this.entry.indexOf(0,0)
		newC1=this.entry.indexOf(0,this.cnt)		
		newC2=this.entry.indexOf(0,this.cnt+1)
		
		
		if(newC0<0){alert("end!!")}

		else if(entry[this.cnt]==0){
			
			this.atCnt(x)

			newC02=this.entry.indexOf(0,0)
			
			if(newC02<0){alert("Finished!!")}		
			else if(newC2>0){ this.cnt=newC2}
			else{ this.cnt=newC0}			
		}
	},
	
	atCnt:function(x){


		if(x==0){newS=1}else{newS=0};
		
		
		newScore=remake(this.score)
		newScore[this.cnt]=newS
		this.score=newScore	
		this.score0=newScore
		
		newT=this.total0[this.cnt]+newS		
		
			
		newTotal=remake(this.total)	
		newTotal[this.cnt]=newT					
		this.total=newTotal	
		this.total0=newTotal
		
		
		newEntry=remake(this.entry)	
		if(newT>this.shresh){newE=1}else{newE=0}	
		newEntry[this.cnt]=newE					
		this.entry=newEntry	
		this.entry0=newEntry				
	},	
  }, //-------methods 

});
</script>